<?xml version="1.0" encoding="iso-8859-1"?>

<!-- 
  -- Please see the readme.txt file included with this distribution for 
  -- attribution and copyright information.
  -->

<root version="2.0">
	<windowclass name="npc_powerlistitem">
		<sizelimits>
			<minimum>
				<height>22</height>
			</minimum>
		</sizelimits>
		<script>
			function sizeChanged()
				local winwidth, winheight = getSize();
				
				local defwidth = math.floor((winwidth - 25) / 3);

				if defwidth ~= action.getSize() then
					action.setAnchoredWidth(defwidth);
					range.setAnchoredWidth(defwidth);
					keywords.setAnchoredWidth(defwidth);
				end
			end
			
			function onDrop(x, y, draginfo)
				if draginfo.isType("dice") then
					for k,v in ipairs(draginfo.getDieList()) do
						if type(v) == "table" then
							dice.addDie(v.type);
						else
							dice.addDie(v);
						end
					end
					return true;
				end
			end

			function onInit()
				if NodeManager.isReadOnly(getDatabaseNode()) then
					shortdescription.setAnchor("top", "name", "bottom", "relative", 3);
				end
			end
		</script>
		<sheetdata>
			<iconcycler name="powertype">
				<anchored>
					<top>
						<anchor>top</anchor>
						<offset>2</offset>
					</top>
					<left>
						<anchor>left</anchor>
						<offset>2</offset>
					</left>
					<size>
						<height>20</height>
						<width>20</width>
					</size>
				</anchored>
				<frame>
					<name>modifier</name>
					<offset>6,5,5,5</offset>
				</frame>
				<stateframe>
					<hover>
						<name>sheetfocus</name>
						<offset>6,5,6,5</offset>
					</hover>
				</stateframe>
				<parameters>
					<icons>indicator_powertype_melee|indicator_powertype_meleebasic|indicator_powertype_ranged|indicator_powertype_rangedbasic|indicator_powertype_close|indicator_powertype_closebasic|indicator_powertype_area|indicator_powertype_aura|indicator_powertype_mr|indicator_powertype_mc|indicator_powertype_ma|indicator_powertype_rc|indicator_powertype_ra|indicator_powertype_ca</icons>
					<values>M|m|R|r|C|c|A|Z|MR|MC|MA|RC|RA|CA</values>
					<tooltips>Melee|Basic melee|Ranged|Basic ranged|Close|Basic close|Area|Aura|Melee or Ranged|Melee or Close|Melee or Area|Ranged or Close|Ranged or Area|Close or Area</tooltips>
				</parameters>
				<script>
					function onInit()
						super.onInit();
						
						if srcnode then
							if NodeManager.isReadOnly(srcnode) then
								setReadOnly(true);
								setStateFrame("hover", nil);
								if getStringValue() == "" then
									setVisible(false);
								end
							end
						end
					end
				</script>
			</iconcycler>

			<windowreferencefield name="link">
				<anchored>
					<right>
						<anchor>right</anchor>
						<offset>-2</offset>
					</right>
					<top>
						<anchor>top</anchor>
						<offset>2</offset>
					</top>
					<size>
						<width>20</width>
						<height>20</height>
					</size>
				</anchored>
				<icon>
					<normal>button_openwindow</normal>
					<empty>button_emptytarget</empty>
					<pressed>button_emptytarget</pressed>
				</icon>
				<allowdrop />
				<script>
					function onInit()
						if getValue() == "" then
							setValue("reference_power_custom", window.getDatabaseNode().getNodeName());
						end
					end
				</script>
			</windowreferencefield>
			
			<npcpowerstring name="name">
				<anchored>
					<top>
						<anchor>top</anchor>
						<offset>5</offset>
					</top>
					<left>
						<parent>powertype</parent>
						<anchor>right</anchor>
						<offset>13</offset>
					</left>
					<right>
						<parent>link</parent>
						<anchor>left</anchor>
						<offset>-7</offset>
					</right>
				</anchored>
				<frame>
					<name>tempmodsmall</name>
					<offset>8,3,8,3</offset>
				</frame>
				<empty>&#171; Power Name &#187;</empty>
				<tabtarget>
					<next>recharge</next>
					<prev>shortdescription</prev>
				</tabtarget>
			</npcpowerstring>
			
			<npcpowerstringmultiline name="recharge">
				<anchored>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>relative</relation>
						<offset>3</offset>
					</top>
					<left>
						<anchor>left</anchor>
						<offset>13</offset>
					</left>
					<right>
						<anchor>right</anchor>
						<offset>-2</offset>
					</right>
				</anchored>
				<empty>&#171; Recharge &#187;</empty>
				<tabtarget>
					<next>action</next>
					<prev>name</prev>
				</tabtarget>
			</npcpowerstringmultiline>

			<npcpowerstringmultiline name="action">
				<empty>&#171; Action &#187;</empty>
				<tabtarget>
					<next>range</next>
					<prev>recharge</prev>
				</tabtarget>
				<anchored>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>relative</relation>
						<offset>3</offset>
					</top>
					<left>
						<anchor>left</anchor>
						<offset>13</offset>
					</left>
					<right>
						<anchor>right</anchor>
						<offset>-2</offset>
					</right>
				</anchored>
			</npcpowerstringmultiline>
			
			<npcpowerstringmultiline name="range">
				<empty>&#171; Range &#187;</empty>
				<tabtarget>
					<next>keywords</next>
					<prev>action</prev>
				</tabtarget>
				<anchored>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>relative</relation>
						<offset>3</offset>
					</top>
					<left>
						<anchor>left</anchor>
						<offset>13</offset>
					</left>
					<right>
						<anchor>right</anchor>
						<offset>-2</offset>
					</right>
				</anchored>
			</npcpowerstringmultiline>
			
			<npcpowerstringmultiline name="keywords">
				<empty>&#171; Keywords &#187;</empty>
				<tabtarget>
					<next>shortdescription</next>
					<prev>range</prev>
				</tabtarget>
				<anchored>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>relative</relation>
						<offset>3</offset>
					</top>
					<left>
						<anchor>left</anchor>
						<offset>13</offset>
					</left>
					<right>
						<anchor>right</anchor>
						<offset>-2</offset>
					</right>
				</anchored>
			</npcpowerstringmultiline>
			
			<diefield name="dice">
				<anchored>
					<left>
						<anchor>left</anchor>
						<offset>12</offset>
					</left>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>relative</relation>
						<offset>4</offset>
					</top>
					<size>
						<width>80</width>
						<height>18</height>
					</size>
				</anchored>
				<frame>
					<name>modifier</name>
					<offset>6,5,5,5</offset>
				</frame>
				<invisible />
				<noreset />
				<script>
					function onInit()
						getDatabaseNode().onUpdate = onValueChanged;
						onValueChanged();
					end

					function onValueChanged(source)
						setVisible(getDatabaseNode().getValue());
					end

					function onDrag(button, x, y, draginfo)
						if dragging then
							return true;
						end
						
						dragging = RulesManager.dragAction(draginfo, "dice", 0, "", nil, getDice());
						
						return true;
					end
					
					function onDragEnd(draginfo)
						dragging = false;
					end

					function onDoubleClick(x,y)	
						return RulesManager.dclkAction("dice", 0, "", nil, nil, getDice(), true);
					end
				</script>
			</diefield>
			
			<powerdescfieldnpc name="shortdescription">
				<anchored>
					<left>
						<anchor>left</anchor>
						<offset>14</offset>
					</left>
					<right>
						<anchor>right</anchor>
						<offset>-2</offset>
					</right>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>relative</relation>
						<offset>3</offset>
					</top>
				</anchored>
				<tabtarget>
					<next>name</next>
					<prev>keywords</prev>
				</tabtarget>
				<script>
					function onInit()
						super.onInit();
						
						if NodeManager.isReadOnly(getDatabaseNode()) then
							if getValue() == "" then
								setVisible(false);
							end
						end
					end
					
					function onDrop(x, y, draginfo)
						if draginfo.isType("dice") then
							window.onDrop(x, y, draginfo);
							return true;
						end
					end
				</script>
			</powerdescfieldnpc>
			
			<genericcontrol>
				<anchored>
					<left>
						<anchor>left</anchor>
					</left>
					<right>
						<anchor>right</anchor>
					</right>
					<top>
						<parent>shortdescription</parent>
						<anchor>bottom</anchor>
						<offset>2</offset>
					</top>
					<size>
						<height>5</height>
					</size>
				</anchored>
			</genericcontrol>
		</sheetdata>
	</windowclass>

	<windowclass name="npc_powers">
		<script>
			function sizeChanged(source)
				powerlist.sizeChanged();
			end

			function onInit()
				--[[ Disabled since only works when window expanded ]]
				--[[ self.onSizeChanged = sizeChanged; ]]
			end
		</script>
		<sheetdata>
			<!-- POWERS -->
			<windowlist name="powerlist">
				<bounds>0,10,-1,-15</bounds>
				<datasource>.powers</datasource>
				<class>npc_powerlistitem</class>
				<allowcreate />
				<allowdelete />
				<script file="scripts/npc_powerlist.lua" />
			</windowlist>
			<scrollercontrol>
				<anchored>
					<to>powerlist</to>
					<position>insidebottomright</position>
					<size>
						<width>45</width>
						<height>27</height>
					</size>
				</anchored>
				<target>powerlist</target>
				<button>
					<normal>button_scroller</normal>
					<pressed>button_scroller_down</pressed>
				</button>
			</scrollercontrol>
		</sheetdata>
	</windowclass>
</root>
